﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication2.Filters
{
    public class MyExceptionFilterAttribute : ActionFilterAttribute, IExceptionFilter
    {
        public void OnException(ExceptionContext filterContext)
        {
            //需求：1 给出提示;2 跳转到指定错误页面;3 告诉系统异步处理完成了
            //1
            string info = filterContext.Exception.Message;
            filterContext.Controller.ViewData["s"] = info;
            //2
            filterContext.Result = new ViewResult()
            {
                ViewName = "Error",
                ViewData = filterContext.Controller.ViewData
            };
            //3
            filterContext.ExceptionHandled = true;
        }
    }
}